package day8Exer;

/*
* 定义乐手弹奏乐器
*
* */
public class Demo3 {

    public static void main(String[] args) {
        //创建乐手对象
        Musician musician = new Musician();

        //创建乐器对象
        Instrument instrument = new Erhu();
        Instrument instrument1 = new Piano();
        Instrument instrument2 = new Violin();

        musician.play(instrument);
        musician.play(instrument1);
        musician.play(instrument2);
    }
}
//定义乐手
class Musician{

    public void play(Instrument instrument){
        instrument.makeSound();
    }
}



//抽象父类 乐器
abstract class Instrument{

    public abstract void makeSound();
}

//二胡
class Erhu extends Instrument{

    @Override
    public void makeSound() {
        System.out.println("使用二胡演奏一曲二泉映月");
    }
}
//钢琴
class Piano extends Instrument{

    @Override
    public void makeSound() {
        System.out.println("使用钢琴演奏一曲两只老虎");
    }
}

//小提琴
class Violin extends Instrument{
    @Override
    public void makeSound() {
        System.out.println("使用小提琴演奏一曲小夜曲");
    }
}